﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MShop.Core.DataAccess;
using MShop.Core;
using MShop.Core.Domain;
using MShop.Core.Util;

namespace MShop.Web.Components.Filters
{
  
    public class RightFilter:System.Web.Mvc.ActionFilterAttribute
    {
        private readonly IShopContext _ShopContext;
        private readonly ICommonDao<WorkSpace> _WorkSpaceDao;
        private readonly ICommonDao<Menu> _MenuDao;

        public RightFilter()
        {
            _WorkSpaceDao = IoC.Resolve<ICommonDao<WorkSpace>>();
            _ShopContext = IoC.Resolve<IShopContext>();
            _MenuDao = IoC.Resolve<ICommonDao<Menu>>();
        }

        public RightFilter(IShopContext shopContext, ICommonDao<WorkSpace> workSpaceDao,ICommonDao<Menu> menuDao)
        {
            _WorkSpaceDao = workSpaceDao;
            _ShopContext = shopContext;
            _MenuDao = menuDao;
        }

        public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.Controller.ViewData["workspaces"]
                    = _WorkSpaceDao.Find(x => x.UserId == _ShopContext.CurrentUser.UserId);
            }
            base.OnActionExecuting(filterContext);
        }
       
    }
}